package com.yidiandao.business.ui.widget.listview.viewholder;

import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.ui.widget.listview.ViewHolder;
import com.yidiandao.business.ui.widget.view.SecondKillStateLayout;
import com.yidiandao.business.ui.widget.view.TimerLayout;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.TextRenderUtils;
import com.yidiandao.business.utils.UIUtils;

/** 首页-天天秒杀-ViewHolder */
public class HomeSecondKillHolder extends ViewHolder {
    public ImageView ivSecondKill;
    public TextView tvEnter;
    public TimerLayout timerLayout;
    public ImageView ivImage1;
    public SecondKillStateLayout killStateLayout1;
    public TextView tvTitle1;
    public TextView tvNewPrice1;
    public TextView tvDeprecatePrice1;
    public LinearLayout rootLayout1;
    public ImageView ivImage2;
    public SecondKillStateLayout killStateLayout2;
    public TextView tvTitle2;
    public TextView tvNewPrice2;
    public TextView tvDeprecatePrice2;
    public LinearLayout rootLayout2;
    public ImageView ivImage3;
    public SecondKillStateLayout killStateLayout3;
    public TextView tvTitle3;
    public TextView tvNewPrice3;
    public TextView tvDeprecatePrice3;
    public LinearLayout rootLayout3;
    private TextView tvTitle;

    @Override
    protected void initView(View rootView) {
        tvTitle = (TextView) rootView.findViewById(R.id.tv_title);
        ivSecondKill = (ImageView) rootView.findViewById(R.id.iv_second_kill);
        tvEnter = (TextView) rootView.findViewById(R.id.tv_enter);
        timerLayout = (TimerLayout) rootView.findViewById(R.id.timer_layout);

        ivImage1 = (ImageView) rootView.findViewById(R.id.iv_image_1);
        killStateLayout1 = (SecondKillStateLayout) rootView.findViewById(R.id.kill_state_layout_1);
        tvTitle1 = (TextView) rootView.findViewById(R.id.tv_title_1);
        tvNewPrice1 = (TextView) rootView.findViewById(R.id.tv_new_price_1);
        tvDeprecatePrice1 = (TextView) rootView.findViewById(R.id.tv_deprecate_price_1);
        rootLayout1 = (LinearLayout) rootView.findViewById(R.id.root_layout_1);

        ivImage2 = (ImageView) rootView.findViewById(R.id.iv_image_2);
        killStateLayout2 = (SecondKillStateLayout) rootView.findViewById(R.id.kill_state_layout_2);
        tvTitle2 = (TextView) rootView.findViewById(R.id.tv_title_2);
        tvNewPrice2 = (TextView) rootView.findViewById(R.id.tv_new_price_2);
        tvDeprecatePrice2 = (TextView) rootView.findViewById(R.id.tv_deprecate_price_2);
        rootLayout2 = (LinearLayout) rootView.findViewById(R.id.root_layout_2);

        ivImage3 = (ImageView) rootView.findViewById(R.id.iv_image_3);
        killStateLayout3 = (SecondKillStateLayout) rootView.findViewById(R.id.kill_state_layout_3);
        tvTitle3 = (TextView) rootView.findViewById(R.id.tv_title_3);
        tvNewPrice3 = (TextView) rootView.findViewById(R.id.tv_new_price_3);
        tvDeprecatePrice3 = (TextView) rootView.findViewById(R.id.tv_deprecate_price_3);
        rootLayout3 = (LinearLayout) rootView.findViewById(R.id.root_layout_3);

        ImageLoader.loadLocalImage(mContext, ivSecondKill, R.mipmap.ic_home_second_kill);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_home_second_kill;
    }

    public void refreshUI1(Goods goods1) {
        tvTitle1.setText(goods1.getGoodsName());
        tvNewPrice1.setText(
                TextRenderUtils.getBeautyPrice(
                        goods1.getLimitPrice(),
                        goods1.getGoodsUnit(),
                        UIUtils.dp2px(16),
                        UIUtils.dp2px(14)));
        tvDeprecatePrice1.setText(
                TextRenderUtils.getBeautyPrice(
                        goods1.getShopPrice(),
                        goods1.getGoodsUnit(),
                        UIUtils.dp2px(13),
                        UIUtils.dp2px(12)));
        tvDeprecatePrice1.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        ImageLoader.loadImageWithPlaceHolder(mContext, ivImage1, goods1.getGoodsThumb());
        killStateLayout1.setState(goods1);
    }

    public void refreshUI2(Goods goods2) {
        tvTitle2.setText(goods2.getGoodsName());
        tvNewPrice2.setText(
                TextRenderUtils.getBeautyPrice(
                        goods2.getLimitPrice(),
                        goods2.getGoodsUnit(),
                        UIUtils.dp2px(16),
                        UIUtils.dp2px(14)));
        tvDeprecatePrice2.setText(
                TextRenderUtils.getBeautyPrice(
                        goods2.getShopPrice(),
                        goods2.getGoodsUnit(),
                        UIUtils.dp2px(13),
                        UIUtils.dp2px(12)));
        tvDeprecatePrice2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        ImageLoader.loadImageWithPlaceHolder(mContext, ivImage2, goods2.getGoodsThumb());
        killStateLayout2.setState(goods2);
    }

    public void refreshUI3(Goods goods3) {
        tvTitle3.setText(goods3.getGoodsName());
        tvNewPrice3.setText(
                TextRenderUtils.getBeautyPrice(
                        goods3.getLimitPrice(),
                        goods3.getGoodsUnit(),
                        UIUtils.dp2px(16),
                        UIUtils.dp2px(14)));
        tvDeprecatePrice3.setText(
                TextRenderUtils.getBeautyPrice(
                        goods3.getShopPrice(),
                        goods3.getGoodsUnit(),
                        UIUtils.dp2px(13),
                        UIUtils.dp2px(12)));
        tvDeprecatePrice3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        ImageLoader.loadImageWithPlaceHolder(mContext, ivImage3, goods3.getGoodsThumb());
        killStateLayout3.setState(goods3);
    }

    public void refreshTitle(String title) {
        tvTitle.setText(title);
    }
}
